# Archlive <http://archlive-pkg.googlecode.com>

pkgname=(open-vm-tools open-vm-tools-modules-cjk)
pkgbase=open-vm-tools
pkgver=2011.04.25
_pkgsubver=402641
pkgrel=1
arch=('i686' 'x86_64')
url="http://open-vm-tools.sourceforge.net/"
license=('LGPL')
makedepends=('chrpath' 'doxygen' 'libdnet' 'icu' 'uriparser' 'kernel26-headers' 'gtkmm')
options=('docs' '!libtool')
source=(http://switch.dl.sourceforge.net/$pkgbase/$pkgbase-$pkgver-${_pkgsubver}.tar.gz
	scripts-network.patch
	scripts-network-FS19541.patch
	open-vm-tools-X11Bool.patch
	open-vm-tools.conf.d
	open-vm-tools.rc.d
	tools.conf
	vmware-guestd
	xautostart.conf)
md5sums=('f6d87599523de31f02aaf229bf2ff08c'
         '06f7448e274db2a911f582e276088fc9'
         'b183ec265200d68431a5e4eb1b0c8cf5'
         '8c333a979578bdc0c3134c1dd6bb7353'
         '79b0a14d86191fee70a4639da8bd7785'
         '67cb83a9e5a4dd016c1a1da2863ca36d'
         'b55d15e2c4be396aad709aeca91033d3'
         '73cc1a2665b0dd62427733d62ead8b9a'
         '75a25d83417e683957321f97a00f8465')

build() {
  cd "$srcdir/$pkgbase-${pkgver}-${_pkgsubver}"
  sed -i 's#-lproc-3.2.7#-lproc-3.2.8#' configure
  [ $NOEXTRACT -eq 1 ] || ./configure --prefix=/usr
  (cd modules && make modules)

  [ $NOEXTRACT -eq 1 ] || {
    sed -i 's#3.2.7#3.2.8#' configure configure.ac
    sed -i 's#CFLAGS="$CFLAGS -Werror"##' configure configure.ac
  }
  ./configure --prefix=/usr --without-kernel-modules
  make
}

package_open-vm-tools() {
  pkgdesc="The Open Virtual Machine Tools (open-vm-tools) are the open source implementation of VMware Tools."
  depends=('open-vm-tools-modules' 'libdnet' 'icu' 'procps' 'glib2' 'uriparser' 'libsigc++' 'libxss')
  optdepends=('gtkmm' 'libnotify' 'libxtst' 'fuse' 'libsm')
  provides=("vmware-tools=$pkgver")
  conflicts=(vmware-tools)
  install=open-vm-tools.install

  cd "$srcdir/$pkgbase-${pkgver}-${_pkgsubver}"

  make DESTDIR=$pkgdir install
  install -D -m 755 scripts/common/vmware-xdg-detect-de $pkgdir/usr/bin/vmware-xdg-detect-de
  chmod 07755 $pkgdir/usr/bin/vmware-user-suid-wrapper

  cd $pkgdir
  patch -Np1 -i $srcdir/scripts-network.patch etc/vmware-tools/scripts/vmware/network
  patch -Np1 -i $srcdir/scripts-network-FS19541.patch etc/vmware-tools/scripts/vmware/network

  ln -fs /usr/sbin/mount.vmhgfs $pkgdir/sbin/mount.vmhgfs

  install -D -m 755 $srcdir/open-vm-tools.rc.d $pkgdir/etc/rc.d/open-vm-tools
  install -D -m 644 $srcdir/open-vm-tools.conf.d $pkgdir/etc/conf.d/open-vm-tools
  install -D -m 644 $srcdir/tools.conf $pkgdir/etc/vmware-tools/tools.conf
  install -D -m 644 $srcdir/xautostart.conf $pkgdir/etc/vmware-tools/xautostart.conf
  install -D -m 644 $srcdir/vmware-guestd $pkgdir/etc/pam.d/vmware-guestd
  rm -rf $pkgdir/usr/etc

  cd $pkgdir && find -type f -exec sh -c "file {} | grep ELF >/dev/null && echo {} && chrpath -d {}" \;
}
package_open-vm-tools-modules-cjk() {
  pkgdesc="The Open Virtual Machine Tools (open-vm-tools) are the open source implementation of VMware Tools."
  provides=("open-vm-tools-modules=$pkgver" "open-vm-tools-modules" "vmware-tools-modules=$pkgver" "vmware-modules=$pkgver")
  conflicts=('vmware-tools-modules' 'vmware-modules')
  install=open-vm-tools-modules.install

  _kernver="$(uname -r)"
  msg "Kernel = ${_kernver}"

  cd "$srcdir/${pkgbase}-${pkgver}-${_pkgsubver}"
  mkdir -p $pkgdir/lib/modules/${_kernver}/misc/
  for MOD in `find -type f -name '*.ko'`; do
    install -D -m644 $MOD $pkgdir/lib/modules/${_kernver}/misc/
  done
  sed -i -e "s/KERNEL_VERSION='.*'/KERNEL_VERSION='${_kernver}'/" $startdir/open-vm-tools-modules.install
  pkgver=${pkgver}_${_kernver/-/_}
}